package com.situ.lession1226.api;

import com.situ.lession1226.model.Community;
import com.situ.lession1226.service.CommunityService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

//对每个电影下面的评论进行展示和增加
@RestController
@RequestMapping(value = "/api/v1/community", produces = "application/json;charset=utf-8")
public class CommunityApi {
    private CommunityService communityService;

    public CommunityApi(CommunityService communityService) {
        this.communityService = communityService;
    }

    @GetMapping("/get")
    public Map<String,Object> get(){
        List <Community> community=communityService.findAllBy();

        if (community == null) {
            return Map.of("success", false);
        } else {
            return Map.of("success",true,"community",community);
        }

    }
    @PostMapping("/post")
    public Map<String, Object> post(Community community){
        boolean success = communityService.save(community);
        return Map.of("success", success);
    }
}
